<?php
//助餐点查询条件

namespace App\Repositories\Filter;

use App\Models\RestaurantModel;

class RestaurantFilter
{


    /**
     * 处理查询条件
     * @param $query
     * @return array[]
     */
    public static function handleQuery($query = [])
    {
        $tableName = (new RestaurantModel())->getTable();

        $where = [];
        $whereIn = [];
        if (!empty($query['id'])) {
            $where[] = ['id', $query['id']];
        }
        if (!empty($query['ids'])) {
            $whereIn[] = ['id', $query['ids']];
        }
        if (!empty($query['activity_id'])) {
            $where[] = ['activity_id', $query['activity_id']];
        }
        if (!empty($query['activity_ids'])) {
            $whereIn[] = ['activity_id', $query['activity_ids']];
        }
        if (!empty($query['title_keyword'])) {
            $where[] = ['title', 'like', '%'.$query['title_keyword'].'%'];
        }
        if (!empty($query['contact_name'])) {
            $where[] = ['contact_name', $query['contact_name']];
        }
        if (!empty($query['contact_phone'])) {
            $where[] = ['contact_phone', $query['contact_phone']];
        }
        if (!empty($query['auth_status'])) {
            $where[] = ['auth_status', $query['auth_status']];
        }
        if (!empty($query['created_at_gte'])) {
            $where[] = ['created_at', '>=', $query['created_at_gte']];
        }
        if (!empty($query['created_at_lte'])) {
            $where[] = ['created_at', '<=', $query['created_at_lte']];
        }
        if (!empty($query['last_auted_at_gte'])) {
            $where[] = ['last_auted_at', '>=', $query['last_auted_at_gte']];
        }
        if (!empty($query['last_auted_at_lte'])) {
            $where[] = ['last_auted_at', '<=', $query['last_auted_at_lte']];
        }

        foreach ($where as &$val) {
            $val[0] = $tableName.'.'.$val[0];
        }
        unset($val);
        foreach ($whereIn as &$val) {
            $val[0] = $tableName.'.'.$val[0];
        }
        unset($val);

        return [
            'where'   => $where,
            'whereIn' => $whereIn,

        ];
    }

}